package xyz.yuzegod.megawalls.classes;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import xyz.yuzegod.megawalls.MegaWalls;
import xyz.yuzegod.megawalls.event.PlayerEnergyChangeEvent;
import xyz.yuzegod.megawalls.game.GamePlayer;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public abstract class Classes implements Listener, Runnable
{
    private static Map<GamePlayer, Integer> addingEnergy;
    private static Map<GamePlayer, Integer> energyPerSeconds;
    private String name;
    private String displayName;
    protected ChatColor nameColor;
    private Material iconType;
    private byte iconData;
    private ClassesType classesType;
    private ClassesInfo.Orientation[] orientations;
    private ClassesInfo.Difficulty difficulty;
    private EquipmentPackage equipmentPackage;
    protected Skill mainSkill;
    protected Skill secondSkill;
    protected Skill thirdSkill;
    protected CollectSkill collectSkill;
    private ClassesSkin defaultSkin;
    
    public Classes(final String name, final String displayName, final ChatColor nameColor, final Material iconType, final byte iconData, final ClassesType classesType, final ClassesInfo.Orientation[] orientations, final ClassesInfo.Difficulty difficulty) {
        this.name = name;
        this.displayName = displayName;
        this.nameColor = nameColor;
        this.iconType = iconType;
        this.iconData = iconData;
        this.classesType = classesType;
        this.orientations = orientations;
        this.difficulty = difficulty;
    }
    
    public void setDefaultSkin(final String value, final String signature) {
        this.defaultSkin = new ClassesSkin("Default", this.getDisplayName(), Arrays.asList("§7" + this.getDisplayName() + "的默认皮肤"), value, signature);
    }
    
    public int energyMelee() {
        return 0;
    }
    
    public int energyBow() {
        return 0;
    }
    
    public abstract String getSkillTip(final GamePlayer p0);
    
    public void run() {
    }
    
    public abstract List<String> getInfo();
    
    public abstract int unlockCost();
    
    public static void startAddEnergyTimer(final GamePlayer gamePlayer, final int seconds, final int energy) {
        if (Classes.addingEnergy.getOrDefault(gamePlayer, 0) > 0) {
            return;
        }
        Classes.energyPerSeconds.put(gamePlayer, energy);
        Classes.addingEnergy.put(gamePlayer, seconds);
    }
    
    public String getName() {
        return this.name;
    }
    
    public String getDisplayName() {
        return this.displayName;
    }
    
    public ChatColor getNameColor() {
        return this.nameColor;
    }
    
    public Material getIconType() {
        return this.iconType;
    }
    
    public byte getIconData() {
        return this.iconData;
    }
    
    public ClassesType getClassesType() {
        return this.classesType;
    }
    
    public ClassesInfo.Orientation[] getOrientations() {
        return this.orientations;
    }
    
    public ClassesInfo.Difficulty getDifficulty() {
        return this.difficulty;
    }
    
    public EquipmentPackage getEquipmentPackage() {
        return this.equipmentPackage;
    }
    
    public void setEquipmentPackage(final EquipmentPackage equipmentPackage) {
        this.equipmentPackage = equipmentPackage;
    }
    
    public Skill getMainSkill() {
        return this.mainSkill;
    }
    
    public void setMainSkill(final Skill mainSkill) {
        this.mainSkill = mainSkill;
    }
    
    public Skill getSecondSkill() {
        return this.secondSkill;
    }
    
    public void setSecondSkill(final Skill secondSkill) {
        this.secondSkill = secondSkill;
    }
    
    public Skill getThirdSkill() {
        return this.thirdSkill;
    }
    
    public void setThirdSkill(final Skill thirdSkill) {
        this.thirdSkill = thirdSkill;
    }
    
    public CollectSkill getCollectSkill() {
        return this.collectSkill;
    }
    
    public void setCollectSkill(final CollectSkill collectSkill) {
        this.collectSkill = collectSkill;
    }
    
    public ClassesSkin getDefaultSkin() {
        return this.defaultSkin;
    }
    
    static {
        Classes.addingEnergy = new HashMap<GamePlayer, Integer>();
        Classes.energyPerSeconds = new HashMap<GamePlayer, Integer>();
        Bukkit.getScheduler().runTaskTimer((Plugin)MegaWalls.getInstance(), (Runnable)new Runnable() {
            @Override
            public void run() {
                for (final Map.Entry<GamePlayer, Integer> entry : Classes.addingEnergy.entrySet()) {
                    if (entry.getValue() > 0) {
                        entry.getKey().addEnergy(Classes.energyPerSeconds.getOrDefault(entry.getKey(), 1), PlayerEnergyChangeEvent.ChangeReason.MAGIC);
                        entry.setValue(entry.getValue() - 1);
                    }
                }
            }
        }, 0L, 20L);
    }
}
